Vector math methodsArray add(vec1, vec2) {vec1 and vec2 are arrays} Adds two vectors. Array sub(vec1, vec2) {vec1 and vec2 are arrays} Subtracts two vectors. Array mul(vec1, amount) {vec1 is an array, amount is a number} Multiplies every element of the vector by the amount. Array div(vec1, amount) {vec1 is an array, amount is a number} Divides every element of the vector by the amount. Number or Array Clamp(value, limit1, limit2) Limits each element between the corresponding values of limit1 and limit2. Number dot(vec1, vec2) {vec1 and vec2 are arrays} Returns a dot product, which is the result of multiplying the two vectors together. Array [2 or 3] cross(vec1, vec2) {vec1 and vec2 are arrays [2 or 3]} Returns a vector cross-product. Refer to a math reference guide or JavaScript guide for more information. Array normalize(vec) {vec is an array} Normalizes the vector so that its length is 1.0. This is a short way of writing div(vec, length(vec)). Number length(vec) {vec is an array} Returns the length of vector vec. Number length(point1, point2) {point1 and point2 are arrays} Returns the distance between two points. Point2 is optional. For example, length(point1, point2) is the same as length(sub(point1, point2)). Array [3] lookAt(fromPt, atPt) {fromPt and atPt are arrays [3]} The argument fromPt is the location in world space of the layer you want to orient. The argument atPt is the point in world space you want to point the layer at. The return value can be used as an expression for the Orientation property, making the layer's z-axis point at atPt. It is especially useful for cameras and lights. For example, lookAt(position, thisComp.layer(1).position). If you use this on a camera, turn off auto-orientation. Note: Vector math functions are global methods that perform operations on arrays, treating them as mathematical vectors. Unlike built-in JavaScript methods, such as Math.sin(), you do not use the Math prefix with these methods. Unless otherwise specified, vector math methods are lenient about dimensions and return a value that is the dimension of the largest array, filling in missing elements with zeros. For example, the expression [10, 20]+[1, 2, 3] returns [11, 22, 3]. |